﻿--[[
   @brief    ui logic of toolbox
   @author   jasonlli
   @version  1.0
   @date     2015-03-16
--]]

sel_action_type = {
    kRepair = "repair",
    kUninstall = "uninstall",
};

sel_action_support_func = {};

tool_box_model = {
    game_id_to_enable_state = {};
    game_id_to_want_pack_state = {};
    show_state = true;
    route_info = {accl_status = 0, router_model = "", vendor = ""};
    pre_update_info_length = 0;
    -- 是否需要路由器密码
    password_need = true;
    my_game_id_list = {};
    my_game_list_info = {};
    game_update_page_opened = false;
    rootId = 0;

    -- tgp route地址
    tgp_web_url = "";
    
    -- 是否首次打开工具箱[用于解决路由器加速开关即时保存]
    is_first_open = true;
    acc_switch_status = 0;

    -- 硬件检测使用数据
    all_game_info = nil;
    game_base_info_ready = false;
    hardware_check_browser_requests = {};

    game_category_type = {
        ALL_GAMES = 0,          --所有游戏
        ROLE_GAMES = 1,         --角色扮演
        COMPETITIVE_GAMES = 2,  --竞技游戏
        WAR_GAMES = 3,          --战争策略
        CASUAL_GAMES = 4,       --休闲游戏
        WEB_GAMES = 5,          --网页游戏
        MOBILE_GAMES = 6,       --手机游戏
        MY_GAMES = 10,          --我的游戏
        HIDDEN_GAMES = 11,      --隐藏游戏
        RECOMMEND_GAMES = 12,   --首页推荐
        GAME_WITH_PRIV = 13,    --特权游戏
        CURRENT_GAME = 14,      --当前游戏
    };
    
    game_category_sort_type = {
        BY_ID = 0,          --按id排序
        BY_NAME = 1,        --按名字排序
        BY_POPULARITY = 2,  --按人气排序
        BY_DATE = 3,        --按日期排序
    };

    game_main_type = {
        MMOG_GAME = 1,
        WEB_GAME = 2,
        CONSOLE_GAME = 3,
        MOBILE_GAME = 4,
    };

    init = function()   
        tool_box_model.all_game_info = banner_model.game_base_info_list; --引用banner_model中的C++对象

        sel_action_support_func[sel_action_type.kRepair] = tool_box_model.is_game_support_fix;
        sel_action_support_func[sel_action_type.kUninstall] = tool_box_model.is_support_uninstall;
    end;

    -- 游戏修复-游戏选项
    get_game_sel_item = function(game_id, action)
        base_utility.log("[tool_box_model][get_repair_game_sel_item]game_id:" ..
                tostring(game_id) .. ", action:" .. tostring(action));

        local base_info = game_utility.get_base_info(game_id);
        if base_info == nil then
            base_utility.log("[tool_box_model][get_repair_game_sel_item]base_info nil",
                    true);
            return nil;
        end
        local game_item = {};
        game_item.game_id = base_info.id;
        game_item.name = base_info.name;
        base_info:delete();

        --[[
        base_utility.log("[tool_box_model][get_repair_game_sel_item]func:" ..
                tostring(sel_action_support_func[action]));
        base_utility.log("[tool_box_model][get_repair_game_sel_item]func:" ..
                tostring(sel_action_support_func[sel_action_type.kRepair]));
        ]]--
        game_item.support = sel_action_support_func[action](game_id);

        return game_item;
    end;

    is_game_support_fix = function(game_id)
        if not game_utility.is_game_support_fix(game_id) then
            base_utility.log("[tool_box_model][is_game_support_fix]not support:" ..
                    "game id:" .. tostring(game_id) ,
                    true);
            return false;
        end

        if not game_utility.can_do_fix(game_id) then
            base_utility.log("[tool_box_model][is_game_support_fix]can not fix, " ..
                    "game id:" .. tostring(game_id), true);
            return false;
        end;

        return true;
    end;

    is_support_uninstall = function(game_id)
        return game_utility.can_do_uninstall(game_id);
    end;
};
tool_box_model.init();
